<!DOCTYPE html>
<html lang="en">
<head>
  <meta charset="UTF-8">
  <meta http-equiv="X-UA-Compatible" content="IE=edge">
  <meta name="viewport" content="width=device-width, initial-scale=1.0">
  <title>扩展运算符应用</title>
</head>
<body>
  <div></div>
  <div></div>
  <div></div>
  <script>
    // 1. 数组的合并
    const kuaizi = ['王太利', '肖央'];
    const fenghuang = ['曾毅', '玲花'];

    // const zuixuanxiaopingguo = kuaizi.concat(fenghuang);
    const zuixuanxiaopingguo = [...kuaizi, ...fenghuang]

    console.log(zuixuanxiaopingguo);

    // 2. 数组的克隆
    const sanzhihua = ['E', 'G', 'M'];
    const sanyecao = [...sanzhihua];

    console.log(sanyecao);

    // 3. 将伪数组转为真正的数组
    const divs = document.querySelectorAll("div");
    const divArr = [...divs];

    console.log(divs)     // NodeList(3) [div, div, div]
    console.log(divArr)   // [div, div, div]

    // 4. 替代apply函数
    let arr = [0, 1, 2]
    let min1 = Math.min.apply(undefined, arr)
    console.log(min1)

    let min2 = Math.min(...arr)
    console.log(min2)

    // 5. 简化函数调用实参的方式
    let date = [2018, 10, 1]
    console.log(new Date(date[0], date[1], date[2]))
    console.log(new Date(...date))

    let time = [10, 28]
    console.log(new Date(...date, ...time, 50))

    // 6. 处理字符串
    let str = "stric"
    str.split("")
    console.log([...str], str.split(""))  // [...str] 不能省略方括号

  </script>
</body>
</html>